package com.greenline.search.test.test;

import com.greenline.search.test.dao.UserObject;
import com.greenline.search.test.dao.DepartmentDao;

import java.util.*;

/**
 * Created with IntelliJ IDEA.
 * User: liulei
 * Date: 13-12-11
 * Time: 下午4:27
 * To change this template use File | Settings | File Templates.
 */
public class GetDepartmentAlias {
    public static void main(String[] args) {
        String concatStr = "&&&&&&&";
        DepartmentDao departmentDao = new DepartmentDao();
        List<UserObject> userObjectList = departmentDao.getAllDepartmentsAlias();
        for(UserObject userObject : userObjectList){
            String departmentNameAndAlias = userObject.getName()+","+userObject.getAlias();
            if(isDuplicated(departmentNameAndAlias)){
                System.out.println(departmentNameAndAlias+"\ttrue");
            }else {
                System.out.println(departmentNameAndAlias);
            }
        }


//        Map<UserObject, List<String>> departmentListMap = new HashMap<UserObject, List<String>>();
//        //format department name and alias to map
//        for(UserObject userObject : userObjectList){
//            List<String> nameList = new ArrayList<String>();
//            nameList.add(userObject.getName());
//            Collections.addAll(nameList, userObject.getAlias().split(","));
//            departmentListMap.put(userObject, nameList);
//        }
//        System.out.println("The department list size is " + userObjectList.size());
//        //print the appropriate name and alias
//        for(List<String> nameList : departmentListMap.values()){
//            for(int i = 0; i < nameList.size(); i++){
//                System.out.print(nameList.get(i));
//                if(i != nameList.size()-1){
//                    System.out.print(",");
//                }
//            }
//            System.out.println();
//        }
//
//
//        for(UserObject userObject : userObjectList){
//            if(isNameAndAliasDuplicated(userObject)){
//                System.out.println("The name and alias have some same name.");
//                System.out.println(userObject.getName()+"\t"+ userObject.getAlias());
//            }
//        }


    }
    //判断科室别名中有没有重复的
//    private static boolean isNameAndAliasDuplicated(UserObject userObject){
//        List<String> deparmentNameList = new ArrayList<String>();
//        deparmentNameList.add(userObject.getName());
//        Collections.addAll(deparmentNameList, userObject.getAlias().split(","));
//        for(int i = 0; i < deparmentNameList.size(); i++){
//            for(int j = i+1; j < deparmentNameList.size(); j++){
//                if(deparmentNameList.get(i).equals(deparmentNameList.get(j))){
//                    return true;
//                }
//            }
//        }
//        return false;
//    }

    private static boolean isDuplicated(String nameAndAlias){
        String[] nameArray = nameAndAlias.split(",");
        for(int i = 0; i < nameArray.length; i++){
            for(int j = i + 1; j < nameArray.length; j++){
                if(nameArray[i].equals(nameArray[j])){
                    return true;
                }
            }
        }
        return false;
    }
}
